class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int ans = 1e8;
        int j = 0;
        int sum = 0;
        for (int i = 0; i < nums.size(); i++) {
            sum += nums[i];
            while (sum - nums[j] >= target) {
                sum -= nums[j++];
            }
            if (sum >= target)ans = min(ans, i - j + 1);
        }
        if (ans == 1e8)ans = 0;
        return ans;
    }
};